﻿using Infrastructure.Web;
using MyData.Dto;
using MyData.Models;
using MyWeb.App_Start;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MyWeb.Controllers
{
    public class HolidayController : BaseController
    {
        // GET: Holiday
        [HandlerLogin]
        public ActionResult HolidayIndex()
        {
            return View();
        }
        [HandlerLogin]
        public ActionResult HolidayEdit(Guid id)
        {
            if (id != Guid.Empty)
            {
                var holiday = HolidayApp.GetHoliday(id);
                return View(holiday);
            }
            return View(new HolidayDto());
        }
        public ActionResult GetHolidays(QueryListModel query, string Name)
        {
            var list = HolidayApp.GetHolidays(query, Name);
            return Json(list, JsonRequestBehavior.AllowGet);
        }
        [HttpPost]
        public JsonResult SaveHoliday(Holiday holiday)
        {
            return base.Try(() =>
            {
                HolidayApp.SaveHoliday(holiday);
            });
        }
        [HttpPost]
        public JsonResult DeleteHoliday(Guid id)
        {
            return base.Try(() =>
            {
                HolidayApp.HolidayDelete(id);
            });
        }
    }
}